import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

import Home from "../views/Home/Home";
import My from "../views/My/My";
import Car from "../views/Car/Car";
const router = new VueRouter({
  routes: [
    {
      path: "/home",
      component: Home,
    },
    {
      path: "/car",
      component: Car,
    },
    {
      path: "/my",
      component: My,
    },
  ],
});
// 全局前置守卫（拦截器）
router.beforeEach((to, from, next) => {
  console.log("to", to);
  console.log("from", from);
  if (to.path && to.path === "/car") {
    if (localStorage.getItem("token")) {
      next();
    }
  } else {
    next();
  }
});
export default router;
